﻿Public Class clsPQCCheck

    Public Function insertPQC(EQUIPNO As String, katamei As String, matlot As String) As Integer

        '更新SQL
        Dim szSql As String = ""
        szSql &= " insert into PER.L_PQC_CHECK(EQUIPNO, KATAMEI, MATLOT) values (?,?,?)"

        insertPQC = DBacs.ExecuteUpdateSql(szSql, -1, EQUIPNO, katamei, matlot)

    End Function

    Public Function updatePQC(EQUIPNO As String, katamei As String, matlot As String) As Integer

        '更新SQL
        Dim szSql As String = ""
        szSql &= " update PER.L_PQC_CHECK set KATAMEI=?, MATLOT=? where EQUIPNO=?  "

        updatePQC = DBacs.ExecuteUpdateSql(szSql, -1, katamei, matlot, EQUIPNO)

    End Function

    Public Sub selectPQC(EQUIPNO As String, ByRef katamei As String, ByRef matlot As String)

        '更新SQL
        Dim szSql As String = ""
        szSql &= " select EQUIPNO, KATAMEI, MATLOT from  PER.L_PQC_CHECK where EQUIPNO = ? "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, EQUIPNO)
        If IsNothing(dt) OrElse dt.Rows.Count > 0 Then
            katamei = IIf(IsDBNull(dt(0)("KATAMEI")), "", dt(0)("KATAMEI"))
            matlot = IIf(IsDBNull(dt(0)("MATLOT")), "", dt(0)("MATLOT"))
        Else
            katamei = ""
            matlot = ""
        End If

    End Sub


    Public Function isSameWaferLot(EQUIPNO As String, WAFER_LOTNO As String) As Boolean
        Dim szSql As String = ""
        Dim rtn As Boolean = False
        szSql &= "SELECT WAFER_LOTNO FROM PER.L_CAR_WAFERLOT where EQUIPNO ='" & EQUIPNO & "' "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)
        If dt.Rows.Count > 0 Then

            If dt.Rows(0)(0).ToString = WAFER_LOTNO Then
                rtn = True
            Else
                rtn = False
            End If
        Else
            insertCarWaferLot(EQUIPNO, WAFER_LOTNO)
            rtn = True
        End If

        Return rtn
    End Function

    Public Sub insertCarWaferLot(EQUIPNO As String, WAFER_LOTNO As String)
        Dim szSql As String = ""
        Dim rtn As Boolean = False
        szSql &= "INSERT INTO PER.L_CAR_WAFERLOT(EQUIPNO, WAFER_LOTNO)  "
        szSql &= " VALUES (?, ?)"
        DBacs.ExecuteUpdateSql(szSql, -1, EQUIPNO, WAFER_LOTNO)

    End Sub
    Public Sub updateCarWaferLot(EQUIPNO As String, WAFER_LOTNO As String)
        Dim szSql As String = ""
        Dim rtn As Boolean = False
        szSql &= "UPDATE PER.L_CAR_WAFERLOT "
        szSql &= "SET WAFER_LOTNO = ? "
        szSql &= "WHERE EQUIPNO = ?"
        DBacs.ExecuteUpdateSql(szSql, -1, WAFER_LOTNO, EQUIPNO)

    End Sub

    Public Function selectPQC_Check(EQUIPNO As String) As DataTable
        Dim szSql As String = ""

        szSql &= "SELECT * FROM PER.L_PLT_PQC_CHECK where EQUIPNO ='" & EQUIPNO & "' "
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)
        If dt.Rows.Count = 0 Then
            szSql = ""
            szSql &= "INSERT INTO PER.L_PLT_PQC_CHECK( EQUIPNO , CLASS_FIRST , ZERO_FIRST_DT , S121_PKG , S122_PKG , PROC_CD)  "
            szSql &= " VALUES (?,?,?,?,?,?)"
            DBacs.ExecuteUpdateSql(szSql, -1, EQUIPNO, "1", "", "", "", "")

            szSql = ""
            szSql &= "SELECT * FROM PER.L_PLT_PQC_CHECK where EQUIPNO ='" & EQUIPNO & "' "
            dt = DBacs.ExecuteSql(szSql, -1)

        End If


        Return dt

    End Function
    Public Sub setClassFirst(EQUIPNO As String)
        Dim szSql As String = ""
        Dim rtn As Boolean = False
        szSql &= "UPDATE PER.L_PLT_PQC_CHECK "
        szSql &= "SET CLASS_FIRST_DT = ? "
        szSql &= "WHERE EQUIPNO = ?"
        DBacs.ExecuteUpdateSql(szSql, -1, setEndTime2, EQUIPNO)
    End Sub

    Public Sub setZeroFirstDT(EQUIPNO As String)
        Dim szSql As String = ""
        Dim rtn As Boolean = False
        Dim strTime As String = ""
        Dim dbCondData As New clsDbCondData
        Dim DBTime As DateTime

        szSql &= "UPDATE PER.L_PLT_PQC_CHECK "
        szSql &= "SET ZERO_FIRST_DT = ? "
        szSql &= "WHERE EQUIPNO = ?"

        DBTime = dbCondData.GetServerTime()
        Dim dt2 As DateTime
        strTime = String.Format("{0}/{1}/{2} 00:00:01", DBTime.Year, DBTime.Month, DBTime.Day)
        If CDate(strTime) < dbCondData.GetServerTime() Then
            dt2 = CDate(strTime).AddDays(1)
        Else
            dt2 = CDate(strTime)
        End If
        DBacs.ExecuteUpdateSql(szSql, -1, dt2, EQUIPNO)
    End Sub
    Public Sub setProcCD(EQUIPNO As String, proc_cd As String)
        Dim szSql As String = ""
        Dim rtn As Boolean = False
        szSql &= "UPDATE PER.L_PLT_PQC_CHECK "
        szSql &= "SET proc_cd = ? "
        szSql &= "WHERE EQUIPNO = ?"
        DBacs.ExecuteUpdateSql(szSql, -1, proc_cd, EQUIPNO)
    End Sub
    Public Sub setS121PKG(EQUIPNO As String, PKG As String)
        Dim szSql As String = ""
        Dim rtn As Boolean = False
        szSql &= "UPDATE PER.L_PLT_PQC_CHECK "
        If PKG = "" Then
            szSql &= "SET S121_PKG = '' "

        Else
            szSql &= "SET S121_PKG = S121_PKG || '" & PKG & "' || '\'"

        End If
        szSql &= " WHERE EQUIPNO = ?"
        DBacs.ExecuteUpdateSql(szSql, -1, EQUIPNO)
    End Sub
    Public Sub setS122PKG(EQUIPNO As String, PKG As String)
        Dim szSql As String = ""
        Dim rtn As Boolean = False
        szSql &= "UPDATE PER.L_PLT_PQC_CHECK "
        If PKG = "" Then
            szSql &= "SET S122_PKG = '' "
        Else
            szSql &= "SET S122_PKG = S122_PKG || '" & PKG & "' || '\'"
        End If
        szSql &= " WHERE EQUIPNO = ?"
        DBacs.ExecuteUpdateSql(szSql, -1, EQUIPNO)
    End Sub

    ''' <summary>
    ''' 检查Lot是否发送过PQC
    ''' </summary>
    ''' <param name="_lot"></param>
    ''' <returns></returns>
    Public Function chkLotPQCSended(_lot As String) As Boolean
        Dim szSql As String = ""
        Dim rtn As Boolean = False
        If _lot = "" Then
            Return True
        End If
        szSql = ""
        szSql &= "SELECT * FROM per.L_PLT_PQC_LOT where KLOTNO =? "
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, _lot)
        If dt.Rows.Count > 0 Then
            rtn = True
        Else
            szSql = " INSERT INTO PER.L_PLT_PQC_LOT(KLOTNO, TOUROKUDATE) VALUES (?, ?) "
            DBacs.ExecuteUpdateSql(szSql, -1, _lot, Now)
            rtn = False
        End If
        '删除大于7天的数据
        szSql = " delete from per.L_PLT_PQC_LOT where  TOUROKUDATE < sysdate - 7 "
        DBacs.ExecuteUpdateSql(szSql, -1)
        Return rtn
    End Function

End Class
